----------------------------------------------------------------------------------
drop table qna_reply;

create table qna_reply(
	qa_re_no number primary key,
	qa_re_ref number,
	qa_re_bno number not null,
	qa_re_content varchar2(1000) not null,
	qa_re_writedate date not null,
	qa_re_restep number not null,
	qa_re_relevel number not null,
	qa_re_id varchar2(50) not null,
	qa_re_adopt number not null,
	constraint fk_qa_re_bno foreign key(qa_re_bno) references javabox_qna_board(no), -- 게시판 글번호
	constraint fk_qa_re_id foreign key(qa_re_id) references javabox_member(id) -- 회원아이디
)

constraint fk_qa_re_bno foreign key(qa_re_bno) references javabox_qna_board(no), -- 게시판 글번호
constraint fk_qa_re_id foreign key(qa_re_id) references javabox_member(id) -- 회원아이디


ALTER TABLE qna_reply DROP CONSTRAINT fk_qa_re_bno;
ALTER TABLE qna_reply ADD CONSTRAINT fk_qa_re_bno FOREIGN KEY (qa_re_bno) 
   REFERENCES javabox_qna_board(no) ON DELETE CASCADE
   
   ALTER TABLE qna_reply DROP CONSTRAINT fk_qa_re_id;
ALTER TABLE qna_reply ADD CONSTRAINT fk_qa_re_id FOREIGN KEY (qa_re_id) 
   REFERENCES javabox_member(id) ON DELETE CASCADE



create sequence qna_reply_seq;

drop sequence qna_reply_seq;

insert into qna_reply values(qna_reply_seq.nextval,104,'홍홍홍홍',sysdate,0,0,'java');

select * from QNA_REPLY where qa_re_bno=21 order by qa_re_ref,qa_re_restep,qa_re_relevel desc;

select * from qna_reply;

select count(*) from qna_reply,discussion_reply where qa_re_id='java'

select qa_re_restep from (select qa_re_restep,CEIL(rownum/1) as num from (select qa_re_restep,CEIL(rownum/1) as num from qna_reply where qa_re_ref=125 order by num desc) order by num desc) where num=1

insert into qna_reply values(qna_reply_seq.nextval,#{ref},#{boardVO.no},#{rcontent},sysdate,#{restep},#{relevel},#{memberVO.id})

update qna_reply set qa_re_adopt=0 where qa_re_no=35;

select qa_re_no,qa_re_ref,qa_re_bno,qa_re_content,to_char(qa_re_writedate, 'yyyy/MM/DD') as rwritedate,qa_re_restep,qa_re_relevel,qa_re_id,qa_re_adopt
from qna_reply
where qa_re_bno=47;






----------------------------------------------------------------------------------
create table qna_reply(
	qa_re_no number primary key,
	qa_re_ref number not null, 
	qa_re_content varchar2(1000) not null,
	qa_re_writedate date not null,
	qa_re_restep number not null,
	qa_re_relevel number not null,
	qa_re_id varchar2(50) not null, 
	 constraint fk_qa_re_ref foreign key(qa_re_ref) references javabox_qna_board(no), -- 게시판 글번호
	  constraint fk_qa_re_id foreign key(qa_re_id) references javabox_member(id) -- 회원아이디
)
create sequence qna_reply_seq;

insert into qna_reply values(qna_reply_seq.nextval,104,'홍홍홍홍',sysdate,0,0,'java');

select * from QNA_REPLY;

select * from qna_reply where qa_re_ref=104;